<!DOCTYPE html>
<html lang="en">
<head>
    <meta name="viewport"
          content="width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1, maximum-scale=1"
          charset="utf-8"/>
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">

    <meta charset="UTF-8">
    <title>app测试</title>
    <script type="text/javascript" src="jquery.js"></script>
    <style>
        .button{padding: 5px;background: #666666;margin: 5px;color: #fff}
    </style>
</head>
<body>
<div>
    <form id="getformtoken">
        <table>
            <thead>
            <tr>
                <td colspan="3"><h4>系统参数配置</h4></td>
            </tr>
            <tr>
                <td>描述</td>
                <td>字段</td>
                <td>值</td>
            </tr>
            </thead>
            <tbody>
            <tr>
                <td>AppID</td>
                <td>AppID</td>
                <td><input name="appID" value=""></td>
            </tr>
            <tr>
                <td>AppSecret</td>
                <td>AppSecret</td>
                <td><input name="appSecret" value=""></td>
            </tr>
            <tr>
                <td>认证网关</td>
                <td>authHost</td>
                <td><input name="authHost" value="http://localhost:8080/gsehcpay"></td>
            </tr>
            <tr>
                <td>默认回调地址</td>
                <td>redirectUrl</td>
                <td><input name="redirectUrl" value="http://localhost/"></td>
            </tr>
            <tr>
                <td>默认回调参数</td>
                <td>responseType</td>
                <td><input name="responseType" value="code"></td>
            </tr>
            <tbody>
            </tbody>

        </table>
        <button type="button" id="getsign">签名</button>
    </form>
    <textarea id="token" rows="5" cols="40"></textarea>
    <div>
        网关<input name="url" id="url" value="http://localhost:8080/gsehcpay/rest/token">
    </div>

    <div>
        <textarea id="tokenok" rows="5" cols="40"></textarea>
    </div>
    <button type="button" id="getToken">获取token</button>

    <div>
        <form action="http://localhost:8080/gsehcpay/h5/auth" method="get">
            <div>
                <table>
                    <thead>
                    <tr>
                        <td>描述</td>
                        <td>字段</td>
                        <td>值</td>
                    </tr>
                    </thead>
                    <tbody>
                    <tr>
                        <td>token</td>
                        <td>token</td>
                        <td><input name="token" id="xxxtoken"/></td>
                    </tr>
                    <tr>
                        <td>回调地址</td>
                        <td>redirectUrl</td>
                        <td><input name="redirectUrl" value="http://localhost"/></td>
                    </tr>
                    <tr>
                        <td>回调状态码</td>
                        <td>responseType</td>
                        <td><input name="responseType" value="code"/></td>
                    </tr>

                    </tbody>
                </table>
            </div>
            <button type="submit">测试点击跳转</button><a href="/login">代码合并点击跳转</a>
        </form>

    </div>
    <div>
        <button type="button" id="getinfo">获取用户信息</button>
        <button type="button" id="accessToken">获取用户accessToken</button>
        <button type="button" id="personCenter">进入个人中心</button>
        <br/>
        <textarea id="getinfotext" rows="5" cols="40"></textarea>
    </div>
    <a class="button" href="qrcode.html">主动扫码</a>
    <a class="button" href="passiveqrcode.html">被动扫码</a>
    <a class="button" href="paybill.html">支付查询</a>
    <a class="button" href="refund.html">退款</a>
    <a class="button" href="refundQuery.html">退款查询</a>
</div>
<script>
    $(function () {
        $("#getsign").click(function () {
            var json = formmap("#getformtoken");
            $.post("/sign", json, function (e) {
                localStorage.setItem("config",JSON.stringify(json))
                $("#token").val(JSON.stringify(e))
            })
        })
        $("#getToken").click(function () {
            debugger;
            var json = {
                url: $("#url").val(),
                sign: $("#token").val()

            };
            $.post("/token", json, function (e) {
                $("#tokenok").val(e)
                try {
                    var parse = JSON.parse(e);
                    $("#xxxtoken").val(parse.rsp.token)
                } catch (a) {
                    alert(e)
                }
            })
        })
        /**
         * 获取用户信息
         */
        $("#getinfo").click(function () {
            $.post("/userinfo", {}, function (e) {
                $("#getinfotext").val(e)
            })
        })
        /**
         * 获取openid
         */
        $("#accessToken").click(function () {

            $.post("/getaccessToken", {}, function (e) {
                $("#getinfotext").val(JSON.stringify(e))
                localStorage.setItem("accessToken", e.accessToken);
            })
        })
        /**
         * 进入个人中心
         */
        $("#personCenter").click(function () {
            var item = localStorage.getItem("accessToken");
            if (!item) {
                alert("请现获取accessToken");
                return;
            }
            location.href = "/qrcode.html"
        })

    })

    /**
     * ajax 分装
     * @param d 传入参数
     * @param a 回调函数
     */
    function ajax(parm, a) {
        parm.type = "post";
        parm.dataType = 'JSON';
        parm.async = false;
        parm.success = a;
        parm.contentType = "application/json"
        parm.beforeSend = function (xhr) {
            xhr.setRequestHeader("Access-Control-Allow-Origin", "*");
        }
        $.ajax(parm);
    }

    /**
     * form转换为json
     * @param dom
     */
    function formmap(dom) {
        var o = {};
        var a = $(dom).serializeArray();
        $.each(a, function () {
            if (o[this.name]) {
                if (!o[this.name].push) {
                    o[this.name] = [o[this.name]];
                }
                o[this.name].push(this.value || '');
            } else {
                o[this.name] = this.value || '';
            }
        });
        return o;
    }
</script>
</body>
</html>